﻿param ($servicename)
Import-AzurePublishSettingsFile 'your credential file.publishsettings'
# Set the default storage account
Get-AzureSubscription | Set-AzureSubscription -CurrentStorageAccount gmstorage

$stoppedvm=get-azurevm -ServiceName $servicename | where {$_.instancestatus -in ('Stopped', 'StoppedDeallocated')}
write ("Found "+$stoppedvm.count+" stopped VMs.")
if ($stoppedvm.count -gt 0)
{
	start-azurevm -ServiceName $servicename -Name $stoppedvm[0].Name
	write ("Starting VM "+$stoppedvm[0].Name)
}
exit $stoppedvm.Count
